package cjm.task5.service;

import cjm.task5.mapper.UserMapper;
import cjm.task5.pojo.Record;
import cjm.task5.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    private static int AdNum = 0;   //id
    private static int UserNum = 0;
    private static int AdNum2 = 0;   //userid
    private static int UserNum2 = 0;
    private static int AdNum3 = 0;   //name
    private static int UserNum3 = 0;
    private static int AdNum4 = 0;   //address
    private static int UserNum4 = 0;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAllUser() {
        return userMapper.findAllUser();
    }

    @Override
    public List<User> findAllAdUser() {
        return userMapper.findAllAdUser();
    }

    @Override
    public void updateLock(Integer id, Integer isLock) {
        userMapper.updateLock(id,isLock);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public User findUserByUserid(String userid) {
        return userMapper.findUserByUserid(userid);
    }


    @Override
    public List<User> findAllAdUserOrder() {
        List<User> users = userMapper.findAllAdUserOrder(AdNum);
        if(AdNum==0){
            AdNum=1;
        }else {
            AdNum=0;
        }
        return users;
    }

    @Override
    public List<User> findAllAdUserOrderByUserId() {
        List<User> users = userMapper.findAllAdUserOrderByUserId(AdNum2);
        if(AdNum2==0){
            AdNum2=1;
        }else {
            AdNum2=0;
        }
        return users;
    }

    @Override
    public List<User> findAllAdUserOrderByName() {
        List<User> users = userMapper.findAllAdUserOrderByName(AdNum3);
        if(AdNum3==0){
            AdNum3=1;
        }else {
            AdNum3=0;
        }
        return users;
    }

    @Override
    public List<User> findAllAdUserOrderByAddress() {
        List<User> users = userMapper.findAllAdUserOrderByAddress(AdNum4);
        if(AdNum4==0){
            AdNum4=1;
        }else {
            AdNum4=0;
        }
        return users;
    }

    @Override
    public List<User> findAllUserOrder() {
        List<User> users = userMapper.findAllUserOrder(UserNum);
        if(UserNum==0){
            UserNum=1;
        }else {
            UserNum=0;
        }
        return users;
    }

    @Override
    public List<User> findAllUserOrderByUserId() {
        List<User> users = userMapper.findAllUserOrderByUserId(UserNum2);
        if(UserNum2==0){
            UserNum2=1;
        }else {
            UserNum2=0;
        }
        return users;
    }

    @Override
    public List<User> findAllUserOrderByName() {
        List<User> users = userMapper.findAllUserOrderByName(UserNum3);
        if(UserNum3==0){
            UserNum3=1;
        }else {
            UserNum3=0;
        }
        return users;
    }

    @Override
    public List<User> findAllUserOrderByAddress() {
        List<User> users = userMapper.findAllUserOrderByAddress(UserNum4);
        if(UserNum4==0){
            UserNum4=1;
        }else {
            UserNum4=0;
        }
        return users;
    }

    @Override
    public List<User> searchAdUser(String keyword) {
        return userMapper.searchAdUser(keyword);
    }

    @Override
    public List<User> searchUser(String keyword) {
        return userMapper.searchUser(keyword);
    }



    @Override
    public User login(String userid, String password) {
        User user = userMapper.login(userid, password);
        return user;
    }

    @Override
    public String getPassword(String userid, String username) {
        String password = userMapper.getPassword(userid, username);
        return password;
    }

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

}
